import request from '@/util/request'

export default {
  namespaced: true,
  state: {
    // 用来保存当前的文章列表
    list: [],
  },
  mutations: {
    changeList(state, newList) {
      state.list = newList
    },
  },
  actions: {
    // channelId 这个参数不用传，可以在内部获取到：this.state.category.activeId
    getList(ctx, channelId) {
      request({
        method: 'GET',
        url: '/v1_0/articles',
        params: {
          channel_id: this.state.category.activeId,
          timestamp: Date.now(),
        },
      }).then(res => {
        console.log(
          '%c [ res ]-17',
          'font-size:13px; background:pink; color:#bf2c9f;',
          res
        )
        ctx.commit('changeList', res.data.data.results)
      })
    },
  },
}
